/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package webservice;

import java.rmi.NotBoundException;
import java.rmi.RemoteException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.servlet.ServletConfig;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.UriInfo;
import javax.ws.rs.PathParam;
import javax.ws.rs.Consumes;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.GET;
import javax.ws.rs.Produces;
import javax.xml.bind.JAXBException;

/**
 * REST Web Service
 *
 * @author xarckane
 */
@Path("wsMonitoring")
public class WsMonitoringResource {

    @Context
    private UriInfo context;

    /**
     * Creates a new instance of WsMonitoringResource
     */
    public WsMonitoringResource() {
    }

    /**
     * Retrieves representation of an instance of
     * webservice.WsMonitoringResource
     *
     * @return an instance of java.lang.String
     */
    @GET
    @Produces("text/xml")
    @Path("/{server}/{requestType}")
    public Object getXml(@PathParam("server") String server, @PathParam("requestType") String request) throws RemoteException, JAXBException {
        
        //TODO return proper representation object
        if (local.Historique.Type.CPU.toString().equalsIgnoreCase(request)) {
            try {
                return rmi.RmiClient.getMonito(server).getCpuReal();
            } catch (NotBoundException ex) {
                Logger.getLogger(WsMonitoringResource.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
        if (local.Historique.Type.MEM.toString().equalsIgnoreCase(request)) {
            try {
                return rmi.RmiClient.getMonito(server).getMemoryReal();
            } catch (NotBoundException ex) {
                Logger.getLogger(WsMonitoringResource.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
        if (local.Historique.Type.PROCESS.toString().equalsIgnoreCase(request)) {
            try {
                return rmi.RmiClient.getMonito(server).getProcessusReal();
            } catch (NotBoundException ex) {
                Logger.getLogger(WsMonitoringResource.class.getName()).log(Level.SEVERE, null, ex);
            }
        } 
       return null;
    }

    /**
     * PUT method for updating or creating an instance of WsMonitoringResource
     *
     * @param content representation for the resource
     * @return an HTTP response with content of the updated or created resource.
     */
    @PUT
    @Consumes("application/xml")
    public void putXml(String content) {
    }
}
